package cn.tedu.net.collection.api;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Locale;

//本类用于测试
public class Test2_String {
    public static void main(String[] args) {
        char[] a=new char[]{'a','b','c'};
        String s=new String(a);
        //这种创建对象的方式底层也会new String(),存放在堆的常量池当中效率高
        String s1="abc";
        System.out.println(s==s1);
        //测试常用方法
        System.out.println(s1.charAt(1));
        System.out.println(s1.concat("cxy"));
        System.out.println(s1.endsWith("c"));
        System.out.println(s1.equals(s));
        System.out.println(s1.getBytes(StandardCharsets.UTF_8));
        System.out.println(s1.indexOf("c"));
        String s2=s1.concat("cxy");
        System.out.println(s2);
        System.out.println(s2.endsWith("xy"));
        s1="abcac";
        System.out.println(s1.lastIndexOf("c"));
        System.out.println(s1.length());
        s1="a b c d e";
        System.out.println(s1.split(" "));
        System.out.println(Arrays.toString(s1.split(" ")));
        System.out.println(s1.startsWith("a"));
        System.out.println(s1.substring(1));
        System.out.println(s1.substring(1,5));
        System.out.println(s1.toUpperCase(Locale.ROOT));
        System.out.println(s1.toLowerCase());
        s1="      abcd     ";
        System.out.println(s1.trim());
        System.out.println(String.valueOf(10));//int转String
        System.out.println(String.valueOf(10)+10);//拼接
        s1="ab  cd";
        System.out.println(s1.codePointBefore(4));//将char类型转换为byte类型
        System.out.println(s1.codePointCount(1,5));//鸡肋 查看中间有几个字符
    }
}
